package xyz.jcat.webmvc.validator;

import xyz.jcat.common.Const;
import xyz.jcat.common.util.RegexUtils;
import xyz.jcat.common.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class PhoneValidator implements ConstraintValidator<Phone, String> {

    @Override
    public boolean isValid(String phone, ConstraintValidatorContext constraintValidatorContext) {
        if(StringUtils.isBlank(phone)){
            return true;
        }
        return RegexUtils.matches(Const.Regex.PHONE, phone);
    }

}
